const mongoose = require("mongoose");
const db = mongoose.createConnection(
  "mongodb://localhost:27017/TechCodeKnowledgeStructure",
  {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  },
  (err) => {
    if (err) {
      console.log("===============================");
      console.log("数据库连接失败:", err);
      console.log("===============================");
      return;
    }
    console.log("数据库连接成功");
  }
);
//设置数据类型(申明哪个字段类型,哪个集合)
const Model = db.model("api", {
  uname: { type: String, default: "武兴师" },
  sex: { type: String },
  pwd: { type: String },
  age: Number,
});
Model.find({})
  .then((res) => {
    console.log(res);
    db.close();
  })
  .catch((err) => console.log(err));
